# -*- coding:utf-8 -*-
# Author : leiyh
# Data ：2019/7/9 21:34
import datetime
import logging
import time


def get_now():
    """获取当前日期,精确到年月日时分秒

    :return: 返回日期格式:2021-11-26 15:20:06
    """
    date_time = str(datetime.datetime.now())[0:19]
    print(date_time)
    return date_time


def get_today():
    """获取当前日期,精确到年月日

    :return: 返回格式:2021-11-26
    """
    date = str(datetime.datetime.now())[0:10]
    print(date)
    return date


def get_time():
    """获取当前时间,只获取时分秒

    :return: 返回日期格式:15:20:06
    """
    time = str(datetime.datetime.now())[11:19]
    print(time)
    return time

def late_time(date_type='history',weeks=13):
    """获取当前之后的N周日期 或者 获取当前日期之前的第N周日期 weeks是外部传入的第几周
    :param weeks: 填写的周数,默认前三个月

    :return: 返回的日期
    """
    try:
        now_time = datetime.datetime.strptime(time.strftime('%Y-%m-%d', time.localtime(time.time())), '%Y-%m-%d')
        if date_type == 'history':
            threeDayAgo = (now_time - datetime.timedelta(weeks=weeks))
        else:
            threeDayAgo = (now_time + datetime.timedelta(weeks=weeks))
        # 转换为时间戳
        # timeStamp = int(time.mktime(threeDayAgo.timetuple()))
        # 转换为其他字符串格式
        otherStyleTime = threeDayAgo.strftime("%Y-%m-%d")
        return otherStyleTime
    except Exception as e:
        logging.error(e)

def get_interval_days(day1, day2):
    """#获取相隔天数

    :param day1: 起始日期:"2020-09-26"
    :param day2: 截止日期:"2021-09-26"
    :return: 返回两个日期之间相隔的天数
    """
    time_array1 = time.strptime(day1, "%Y-%m-%d")
    timestamp_day1 = int(time.mktime(time_array1))
    time_array2 = time.strptime(day2, "%Y-%m-%d")
    timestamp_day2 = int(time.mktime(time_array2))
    days = (timestamp_day2 - timestamp_day1) // 60 // 60 // 24
    return days


if __name__ == '__main__':
    get_now()
    get_today()
    get_time()


